package com.zw.blog.config;

import com.zw.blog.exception.NotFoundException;
import com.zw.blog.util.UploadUtils;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 为了防止重启项目才能看到新上传的图片(目前没啥用）
 * 可以映射根目录新上传的资源
 */
@Configuration
public class UploadConfig implements WebMvcConfigurer {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
//映射图片保存地址
        try {
            registry.addResourceHandler("/images/blogImages/**").addResourceLocations("file:" + UploadUtils.ABSOLUTE_BLOG_IMAGES_PATH);
        } catch (NotFoundException e) {
            e.printStackTrace();
        }
    }
}
